package cn.lianyutiantang;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication
@MapperScan("cn.lianyutiantang.dao")
@EnableScheduling  //启动定时扫描
public class FileServerApplication extends WebMvcConfigurationSupport {

	/**
	 * 默认跳转前端首页
	 */
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("index");
		super.addViewControllers(registry);
	}
//redirect:/pc/index.html#/
	public static void main(String[] args) {
		SpringApplication.run(FileServerApplication.class, args);
	}
	/**
	 * 上传限制设置
	 * @return
	 */
	@Bean
	public MultipartConfigElement multipartConfigElement(){
		MultipartConfigFactory config = new MultipartConfigFactory();
		//上传最大限制
		config.setMaxFileSize("80MB");
		//请求最大限制
		config.setMaxRequestSize("100MB");
		return config.createMultipartConfig();
	}
}
